import {LogLanguage} from "../dist/index.js"

// 综合测试用例
const testCases = [
  // 基本日志级别
  'INFO Basic log message',
  'ERROR Error occurred',
  'WARN Warning message',
  
  // 带字符串的日志
  'INFO User "john_doe" logged in',
  'ERROR Database "main_db" connection failed',
  'DEBUG Processing request `{"id": 123}`',
  
  // 带数值的日志
  'INFO Response time=0.123s',
  'ERROR Retry count: 5',
  'DEBUG Memory usage: 1024.5MB',
  
  // 带类路径的日志
  'INFO [service.AuthService] User authenticated',
  'ERROR (com.example.MyClass:123) Exception occurred',
  
  // 带事务ID的日志
  'INFO [TID:abc123] Request processed',
  
  // 复杂日志行
  '2024-01-15T10:30:45.123+0800 INFO [TID:abc123] [service.AuthService] User "admin" logged in with session_id="sess_456" after 0.25s'
]

console.log("Comprehensive testing of LogLanguage parser...")

testCases.forEach((testCase, index) => {
  console.log(`\nTest case ${index + 1}:`)
  console.log(`Input: ${testCase}`)
  
  try {
    const tree = LogLanguage.parser.parse(testCase)
    console.log("✅ Parse successful!")
    
    // 检查所有节点
    let foundElements = {
      FATALExpression: [],
      ERRORExpression: [],
      INFOExpression: [],
      WARNINGExpression: [],
      DebugExpression: [],
      DATEExpression: [],
      CLASSPATHExpression: [],
      TIDExpression: [],
      StringLiteral: [],
      NumberExpression: []
    }
    
    tree.iterate({
      enter: (node) => {
        const text = testCase.slice(node.from, node.to)
        if (foundElements.hasOwnProperty(node.name)) {
          foundElements[node.name].push(text)
        }
      }
    })
    
    // 输出结果
    Object.entries(foundElements).forEach(([name, elements]) => {
      if (elements.length > 0) {
        console.log(`✅ Found ${elements.length} ${name}: ${elements.join(', ')}`)
      }
    })
    
    // 检查是否有任何元素被识别
    const totalElements = Object.values(foundElements).flat().length
    if (totalElements === 0) {
      console.log("❌ No special elements found")
    }
    
  } catch (error) {
    console.log(`❌ Parse failed: ${error.message}`)
  }
}) 